program BrainFuck;

var
  Command: Char;
  Memory: array[0..30000] of Char;
  CurrentCell: Integer = 0;
  CurrentPos: Integer = 0;
  I: Integer;
  Syntax: set of char = ['+', '-', '<', '>', '[', ']', '.', ','];
  Prog: String;

procedure SeekEndOfCycle;
var
  Depth: Integer;
begin
  Depth := 1;
  repeat
    Command := Prog[CurrentPos];
    inc(CurrentPos);
    case Command of
      '[': Inc(Depth);
      ']': Dec(Depth);
    end;
  until Depth = 0;
end;

procedure Cycle;
var
  Depth, I: Integer;
begin
  Depth := 1;
  while Depth > 0 do
  begin
    Command := Prog[CurrentPos];
    inc(CurrentPos);
    case Command of
      '>': Inc(CurrentCell);
      '<': Dec(CurrentCell);
      '.': Write(ord(Memory[CurrentCell]), ' ');
      '+': Inc(Memory[CurrentCell]);
      '-': Dec(Memory[CurrentCell]);
      ']': Dec(Depth);
      '[':
      begin
        if Memory[CurrentCell] <> chr(0) then
        begin
          I := CurrentPos;
          while Memory[CurrentCell] <> chr(0) do
          begin
            Cycle;
            CurrentPos := I;
          end;
          SeekEndOfCycle;
        end
        else
        begin
          SeekEndOfCycle;
        end;
      end;
    end;
  end;
end;

begin
  for I := 0 to 30000 do
  begin
    Memory[I] := chr(0);
  end;
  prog := '';
  while true do
  begin
    Read(Command);
    if Command = '!' then break;
    if Command in Syntax then
      prog := prog + Command;
  end;

  while CurrentPos <= Length(prog) do
  begin
    Command := prog[CurrentPos];
    inc(CurrentPos);
    case Command of
      '>': Inc(CurrentCell);
      '<': Dec(CurrentCell);
      '.': Write(ord(Memory[CurrentCell]), ' ');
      '+': Inc(Memory[CurrentCell]);
      '-': Dec(Memory[CurrentCell]);
      '[':
      begin
        if Memory[CurrentCell] <> chr(0) then
        begin
          I := CurrentPos;
          while Memory[CurrentCell] <> chr(0) do
          begin
            Cycle;
            CurrentPos := I;
          end;
          SeekEndOfCycle;
        end
        else
        begin
          SeekEndOfCycle;
        end;
      end;
    end;
  end;
end.
